package site.luojie.utils;

import site.luojie.core.annotation.Autowired;
import site.luojie.core.annotation.Component;

import java.sql.SQLException;

/**
 * @Description: 事务管理器
 * @Author jie.luo
 * @Create: 2020-05-02 08:09
 **/
@Component
public class TransactionManager {

    @Autowired
    private ConnectionUtils connectionUtils;

    public void beginTransaction() throws SQLException {
        connectionUtils.getCurrentThreadConnection().setAutoCommit(false);
    }

    public void commitTransaction() throws SQLException {
        connectionUtils.getCurrentThreadConnection().commit();
    }

    public void rollbackTransaction() throws SQLException {
        connectionUtils.getCurrentThreadConnection().rollback();
    }

}
